package com.myecl.poker.state;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;
import java.util.List;

import com.myecl.poker.communication.ViewData;
import com.myecl.poker.rules.Card;


public class Player {
//	PlayerView playerView;
	private Socket socket;		
	private ObjectOutputStream objectOutput;
	private ObjectInputStream objectInput;	

	private String name;
	
	private List<Card> cards;
	private double chips;

	
	public Player(Socket socket, ObjectOutputStream objectOutput, 
			ObjectInputStream objectInput, String name) {
		this.socket = socket;
		this.objectOutput = objectOutput;
		this.objectInput = objectInput;
		this.name = name;
	}

	public void sendViewData(ViewData viewData) {
		 try {
			objectOutput.writeObject(viewData);
		} catch (IOException e) {
			e.printStackTrace();
		}  
	}

	public void setCards(List<Card> cards) {
		this.cards = cards;
	}
	
	public List<Card> getCards() {
		return cards;
	}
	
	public ObjectInputStream getObjectInputStream() {
		return objectInput;
	}
	
	public double bid(double bid)  {
		assert bid >= 0;
		double chipsForPot = chips >= bid ? bid : chips;
		chips = chips >= bid ? chips - bid : 0;
		return chipsForPot;
		
	}


	public String getName() {
		return name;
	}
}
